home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtool17.zip / TVTOOLS.ZIP / GENCOLL.CPP < prev    next >
C/C++ Source or Header  |  1993-06-10  |  1KB  |  79 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #define Uses_TGenCollection
  4. #include "tvtools.h"
  5. #include "strings.h"
  6.  
  7.  
  8.  
  9. TGenCollection::TGenCollection( ccIndex aLimit, ccIndex aDelta )
  10.                  :TStringCollection( aLimit, aDelta )
  11. {
  12. }
  13.  
  14.  
  15. char *TGenCollection::getText( ccIndex index )
  16. {
  17.  return (char *) at(index);
  18. }
  19.  
  20.  
  21. int TGenCollection::compare( void *str1, void *str2 )
  22. {
  23.  return strcomp( (char *)str1, (char *)str2 );
  24. }
  25.  
  26. int TGenCollection::getCount()
  27. {
  28.  return count;
  29. }
  30.  
  31. int TGenCollection::getTextLength()
  32. {
  33.  int len = 0;
  34.  for ( ccIndex i = 0; i < getCount(); i++ )
  35.      len = max( len, strlen(getText(i)) );
  36.  
  37.  return len;
  38. }
  39.  
  40.  
  41.  
  42. ccIndex TGenCollection::indexOf( char *item )
  43. {
  44.  for ( ccIndex i = 0; i < getCount(); i++ )
  45.      if ( ! strcmp(item, getData(i)) ) return i;
  46.  
  47.  return ccNotFound;
  48. }
  49.  
  50.  
  51. ccIndex TGenCollection::indexOfText( char *item )
  52. {
  53.  for ( ccIndex i = 0; i < getCount(); i++ )
  54.      if ( ! strcmp(item, getText(i)) ) return i;
  55.  
  56.  return ccNotFound;
  57. }
  58.  
  59.  
  60. void *TGenCollection::firstThat( ccTestFunc Test, void *arg )
  61. {
  62.  for ( ccIndex i = 0; i < getCount(); i++ )
  63.     {
  64.      char *data = getData(i);
  65.      if ( Test(data, arg) ) return data;
  66.     }
  67.  return 0;
  68. }
  69.  
  70.  
  71. void *TGenCollection::firstTextThat( ccTestFunc Test, void *arg )
  72. {
  73.  for ( ccIndex i = 0; i < getCount(); i++ )
  74.     {
  75.      char *data = getText(i);
  76.      if ( Test(data, arg) ) return data;
  77.     }
  78.  return 0;
  79. }